<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加性质</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
    <script src="/static/lib/layui/layui.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <div class="layui-form-item">
            <label class="layui-form-label">性质代码<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="type_code" placeholder="请输入性质代码，且不重复！" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性质名称<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="type_name" placeholder="请输入性质名称" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="checkbox" id="now_status" name="now_status" lay-skin="switch" lay-text="启用|停用" checked="checked">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark_describe" placeholder="请输入备注内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script>
    layui.use(["form", "okUtils", "form", "okLayer"], function () {
        let $ = layui.$;
        let form = layui.form;
        let okUtils = layui.okUtils;
        let okLayer = layui.okLayer;
        let tree = layui.tree;
        okLoading.close();
        // 这里得把switch的状态弄对，不然，如果他创建就停用，数据就传不过去了
        form.on("submit(add)",function (data) {
            if(data.field.now_status=="on"){
                data.field.now_status=0;
            }else{
                data.field.now_status=1;
            }
            okUtils.ajax("/customer/industry/","post",data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
					parent.layer.close(parent.layer.getFrameIndex(window.name));
				});
            }).fail(function (error) {
                // 这里已经有提示了
            });
            return false;
        });
    });
</script>
</body>
</html>
